%% Equity Target price estimates
% Computes equity target prices using different approaches
%% Rights and disclaimer
% Author: Benjamin J. J. Voigt (bvoigt@gmail.com)
% Published: Oct 2012
% Version: 0.0.1
% License: BSD 2-Clause, free to use and copy retaining original author reference
% 
% Disclaimer: USE AT YOUR OWN RISK; NO INVESTMENT RECOMMENDATION IMPLIED;
% NOT ASSOCIATED WITH PAST, CURRENT OR FUTURE EMPLOYER OR ASSOCIATES OF THE
% AUTHOR; DO NOT USE THIS CODE TO INVEST YOUR OWN MONEY OR TO 
% ENCOURAGE OTHERS TO INVEST MONEY;
%% Syntax
% aaa
%% Arguments
% bbb
%% Examples
% ccc
%% Required toolboxes
% Financial Toolbox, Data Feed Toolbox, Statistics
% Toolbox
%% Purpose and notes
% Purpose: Estimate equity target prices
%
% Notes: --
%
% Known limitations:
% 1) Sourced prices are colected from Yahoo finance, which redistributes
% Thomson/First Call mean target estimate, if available, which likely
% has some degree of consensus bias.
% 2) If Thomson/First Call data is unavailable the current price is used
% to estimte the target price
% TODO: check if wights get set to 0 if alphas result zero, because if 
% there are no alpha estimates the stock should be excluded from the
% stock universe to start with!
%

function [target] = EQTargetPriceEst(symbol_cell, target_est_source)
% Global, function wide variables 
g_connect = yahoo;
g_symbol_cell = symbol_cell;
g_target_est_source = target_est_source;


% Local, dummy, loop or sub-section specific variables
l_symbol_target_price = zeros(length(g_symbol_cell),1);
l_dummy = 0;

switch g_target_est_source
    case 'sourced'
        for i=1:length(g_symbol_cell)
            l_symbol_target_price = LoadData('yql', ...
                g_symbol_cell(1,i), 'Target price', ...
                '','', '')
            if strcmp(cellstr(l_symbol_target_price),'N/A')
                l_symbol_target_price = LoadData('datafeed_last', ...
                    g_symbol_cell(1,i),'','','','')
                
            end
            target(1,i) = str2num(l_symbol_target_price)
        end
    case 'internal'
    otherwise
        % TODO: error message
        ;
end
% TODO: For testing return the following, remove when not testing
target = [30.8763 25.1955 39.8398 48.4205 55.7005 52.8618];

